/*******************************************************************************
 * Level Master 2000
 * Copyright (C) 2010 Christian Herzog
 * For more information see http://code.google.com/p/levelmaster2000/
 *
 * This file is licensed under the terms of the MIT license, see
 * http://www.opensource.org/licenses/mit-license.php for further information.
 ******************************************************************************/

#include "CreateGroupCommand.h"

#include <QUndoCommand>

#include "../EntityExplorer.h"
#include "../Group.h"
#include "../LevelMaster2000.h"

CreateGroupCommand::CreateGroupCommand( EntityExplorer* entityExplorer,
                     QString name,
                     QString parentGroup,
                     QUndoCommand *parent )
                         : QUndoCommand( parent ),
                         entityExplorer( entityExplorer ),
                         name( name ),
                         parentGroup( parentGroup )
{
    init();
}

void CreateGroupCommand::init()
{
    setText( "Create Group \"" + name + "\"" );
}

void CreateGroupCommand::undo()
{
    if( !LevelMaster2000::DISALLOW_NEW_COMMAND )
    {
        LevelMaster2000::DISALLOW_NEW_COMMAND++;
        {
            entityExplorer->deleteGroup( name );
        }
        LevelMaster2000::DISALLOW_NEW_COMMAND--;
    }
}

void CreateGroupCommand::redo()
{
    if( !LevelMaster2000::DISALLOW_NEW_COMMAND )
    {
        LevelMaster2000::DISALLOW_NEW_COMMAND++;
        {
            entityExplorer->createGroup( name, parentGroup );
        }
        LevelMaster2000::DISALLOW_NEW_COMMAND--;
    }
}
